{% extends 'admin/layout.html' %}
{% import 'admin/_macros.html' as lib with context %}

{% block head_css %}
    <link href="{{ url_for('admin.static', filename='css/file.css') }}" rel="stylesheet">
    {{super()}}
{% endblock %}


{% block body %}
    <h1 id="main-title">{{_gettext('Files')}}</h1>
    {% if admin_view.can_upload %}
    <a class="btn btn-primary btn-title" href="{{ get_dir_url('.upload', path=dir_path) }}">{{ _gettext('Upload File') }}</a>
    {% endif %}
    {% if admin_view.can_mkdir %}
    <a class="btn btn-primary btn-title" href="{{ get_dir_url('.mkdir', path=dir_path) }}">{{ _gettext('Create Directory') }}</a>
    {% endif %}
    <div class="clearfix"></div>
    <hr />
    <ul id="file-paths">
        <li>
            <a href="{{ get_dir_url('.index', path=None) }}">{{ base_path.split('/')[-1] }}</a>
        </li>
        {% for name, path in breadcrumbs[:-1] %}
        <li>
            <span class="divider">/</span><a href="{{ get_dir_url('.index', path=path) }}">{{ name }}</a>
        </li>
        {% endfor %}
        {% if breadcrumbs %}
        <li>
            <span class="divider">/</span><a href="{{ get_dir_url('.index', path=breadcrumbs[-1][1]) }}">{{ breadcrumbs[-1][0] }}</a>
        </li>
        {% endif %}
    </ul>

    <table class="table table-striped table-bordered model-list">
        <thead>
            <tr>
                <th class="span1">&nbsp;</th>
                <th>Name</th>
                <th>Size</th>
            </tr>
        </thead>
        {% for name, path, is_dir, size in items %}
        <tr>
            <td>
                {% if admin_view.can_rename and path and name != '..' %}
                <a class="icon" href="{{ url_for('.rename', path=path) }}">
                        <i class="icon-pencil"></i>
                </a>
                {% endif %}
                {%- if admin_view.can_delete and path -%}
                    {% if is_dir %}
                        {% if name != '..' and admin_view.can_delete_dirs %}
                        <form class="icon" method="POST" action="{{ url_for('.delete') }}">
                            <input type="hidden" name="path" value="{{ path }}"></input>
                            <button onclick="return confirm('{{ _gettext('Are you sure you want to delete \\\'%(name)s\\\' recursively?', name=name) }}')">
                                <i class="icon-remove"></i>
                            </button>
                        </form>
                        {% endif %}
                    {% else %}
                    <form class="icon" method="POST" action="{{ url_for('.delete') }}">
                        <input type="hidden" name="path" value="{{ path }}"></input>
                        <button onclick="return confirm('{{ _gettext('Are you sure you want to delete \\\'%(name)s\\\'?', name=name) }}')">
                            <i class="icon-remove"></i>
                        </button>
                    </form>
                    {% endif %}
                {%- endif -%}
            </td>
            {% if is_dir %}
            <td colspan="2">
                <a href="{{ get_dir_url('.index', path)|safe }}">
                    <i class="icon-folder-close"></i> <span>{{ name }}</span>
                </a>
            </td>
            {% else %}
            <td>
                <a href="{{ get_file_url(path)|safe }}">{{ name }}</a>
            </td>
            <td>
                {{ size }}
            </td>
            {% endif %}
        </tr>
        {% endfor %}
    </table>
{% endblock %}
